<?php
include_once '../header1.php';
?>
<link rel="stylesheet" href="../css/datepicker.css" type="text/css" />
    <link rel="stylesheet" media="screen" type="text/css" href="../css/layout.css" />
  	<script type="text/javascript" src="../js/jquery.js"></script>
	<script type="text/javascript" src="../js/datepicker.js"></script>
    <script type="text/javascript" src="../js/eye.js"></script>
    <script type="text/javascript" src="../js/utils.js"></script>
    <script type="text/javascript" src="../js/layout.js?ver=1.0.2"></script>
<script type="text/javascript">
function getHttpRequest()
{
if(window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
return xmlhttp;
}
</script>
<script type="text/javascript">
function DeleteVerification(rownum,variables)
{
	var rownum=rownum;
	var id="Verifi";
	var r=confirm("Are you sure to delete this?");
if(r==true)
{
document.getElementById(id).value=variables;
}
}
</script>
<script type="text/javascript">
function GetTBox(tbox,rows)
{
	var i;
	var box="groupcolumn"+tbox;
	for(i=1;i<=rows;i++)
	{
		var tb="groupcolumn"+i;
		var b="button"+i;
		if(tb!=box)
		{
		document.getElementById(tb).value="";
		document.getElementById(b).innerHTML="";
		}
	}
	
}
</script>
<script type="text/javascript">
function GetCol(val,name,rownum)
{
	var rownum=rownum;
	var xmlhttp; 
var b="button"+rownum;
var n=val+","+rownum+","+name;
if (val=="")
  {
  document.getElementById(b).innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest();
  }
else
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
   document.getElementById(b).innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","butt.php?q="+n,true);
xmlhttp.send();
}
</script>
</head>
<body>
<?php

include_once ("../Login/databaseconnection.php");
if(!loggedin())
{
require_once ("../index.php");
}
   
   else
   {
   $action="";
    if(!isset($_POST['gby'])&&!isset($_POST['groupback']))
  {
	   $_SESSION['sele_groupby']="";
	   $_SESSION['back_groupby']=0;	
 $_SESSION['Column_name']="";	
$_SESSION['gvals']=""; 
}	   
	   $action="";
  if(isset($_POST['gby']))
  {
	  $action="group";
	 $crvalues=$_POST['crval'];
	 $crvalu=explode(",",$crvalues);
	 $Column=$crvalu[0];
	  $rownum=$crvalu[1];
     $pri_keys=$_POST['pri'];
	 $prikeys=explode(",",$pri_keys);
	 $T_NIC_Number=$prikeys[0];
    	 if(empty($_SESSION['sele_groupby']))
	  {
		 $_SESSION['sele_groupby']=$pri_keys.",".$Column;
	  }
	  else
	  {
		 $_SESSION['sele_groupby']=$_SESSION['sele_groupby']."_".$pri_keys.",".$Column;
	  } 
	  
$sele_groupby=explode("_",$_SESSION['sele_groupby']);
if($Column==1)
{
if(empty( $_SESSION['Column_name']))
{
 $_SESSION['Column_name']="T_NIC_Number";
}
else
{
 $_SESSION['Column_name']= $_SESSION['Column_name'].",T_NIC_Number";
}
}
if($Column==2)
{
if(empty( $_SESSION['Column_name']))
{
 $_SESSION['Column_name']="School_Id";
}
else
{
 $_SESSION['Column_name']= $_SESSION['Column_name'].",School_Id";
}
}
if($Column==3)
{
if(empty( $_SESSION['Column_name']))
{
 $_SESSION['Column_name']="First_Name";
}
else
{
 $_SESSION['Column_name']= $_SESSION['Column_name'].",First_Name";
}
}
if($Column==4)
{
if(empty( $_SESSION['Column_name']))
{
 $_SESSION['Column_name']="Last_Name";
}
else
{
 $_SESSION['Column_name']= $_SESSION['Column_name'].",Last_Name";
}
}
 if($Column==5)
{
if(empty( $_SESSION['Column_name']))
{
 $_SESSION['Column_name']="Date_Of_Birth";
}
else
{
 $_SESSION['Column_name']= $_SESSION['Column_name'].",Date_Of_Birth";
}
}
if($Column==6)
{
if(empty( $_SESSION['Column_name']))
{
 $_SESSION['Column_name']="Gender";
}
else
{
$_SESSION['Column_name']= $_SESSION['Column_name'].",Gender";
}
} 	
if($Column==7)
{
if(empty( $_SESSION['Column_name']))
{
 $_SESSION['Column_name']="Nature_Of_Appointment";
}
else
{
 $_SESSION['Column_name']= $_SESSION['Column_name'].",Nature_Of_Appointment";
}
}
if($Column==8)
{
if(empty( $_SESSION['Column_name']))
{
 $_SESSION['Column_name']="Service";
}
else
{
 $_SESSION['Column_name']= $_SESSION['Column_name'].",Service";
}
}
if($Column==9)
{
if(empty( $_SESSION['Column_name']))
{
 $_SESSION['Column_name']="Academic_Qualifications";
}
else
{
 $_SESSION['Column_name']= $_SESSION['Column_name'].",Academic_Qualifications";
}
} 	 	 
if($Column==10)
{
if(empty( $_SESSION['Column_name']))
{
 $_SESSION['Column_name']="Professional_Qualifications";
}
else
{
 $_SESSION['Column_name']= $_SESSION['Column_name'].",Professional_Qualifications";
}
}
if($Column==11)
{
if(empty( $_SESSION['Column_name']))
{
 $_SESSION['Column_name']="Specialised_In";
}
else
{
 $_SESSION['Column_name']= $_SESSION['Column_name'].",Specialised_In";
}
}
if($Column==12)
{
if(empty( $_SESSION['Column_name']))
{
 $_SESSION['Column_name']="Achievements_Awards";
}
else
{
 $_SESSION['Column_name']= $_SESSION['Column_name'].",Achievements_Awards";
}
}	
if($Column==13)
{
if(empty( $_SESSION['Column_name']))
{
 $_SESSION['Column_name']="Address";
}
else
{
 $_SESSION['Column_name']= $_SESSION['Column_name'].",Address";
}
}
if($Column==14)
{
if(empty( $_SESSION['Column_name']))
{
 $_SESSION['Column_name']="Mobile_Tp_Number";
}
else
{
 $_SESSION['Column_name']= $_SESSION['Column_name'].",Mobile_Tp_Number";
}
}
if($Column==15)
{
if(empty( $_SESSION['Column_name']))
{
 $_SESSION['Column_name']="Home_Tp_Number";
}
else
{
 $_SESSION['Column_name']= $_SESSION['Column_name'].",Home_Tp_Number";
}
}
if($Column==16)
{
if(empty( $_SESSION['Column_name']))
{
 $_SESSION['Column_name']="Office_Tp_Number";
}
else
{
 $_SESSION['Column_name']= $_SESSION['Column_name'].",Office_Tp_Number";
}
} 	 	 	 	 	 	
	if($Column==17)
{
if(empty( $_SESSION['Column_name']))
{
 $_SESSION['Column_name']="Role";
}
else
{
 $_SESSION['Column_name']= $_SESSION['Column_name'].",Role";
}
} 
if($Column==18)
{
if(empty( $_SESSION['Column_name']))
{
 $_SESSION['Column_name']="Appointment_Date";
}
else
{
 $_SESSION['Column_name']= $_SESSION['Column_name'].",Appointment_Date";
}
}
if($Column==19)
{
if(empty( $_SESSION['Column_name']))
{
 $_SESSION['Column_name']="Appointed_Subject";
}
else
{
 $_SESSION['Column_name']= $_SESSION['Column_name'].",Appointed_Subject";
}
}
if($Column==20)
{
if(empty( $_SESSION['Column_name']))
{
 $_SESSION['Column_name']="Last_Updated_Date";
}
else
{
 $_SESSION['Column_name']= $_SESSION['Column_name'].",Last_Updated_Date";
}
}
  $Column_names=explode(",", $_SESSION['Column_name']);
  $tot_cols=count($Column_names);
  $Exc_que="SELECT * FROM teacher WHERE T_NIC_Number='".$T_NIC_Number."'";
 $gro=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='".$T_NIC_Number."'");
   $number_of_rows=mysql_num_rows($gro);
if($rowgro=mysql_fetch_array($gro))
{
$Col_name=$Column_names[$tot_cols-1];
if($rowgro[$Col_name]=="")
{
$_SESSION['value_empty']="Sorry,the column value is empty";
}
else
{
if(empty($_SESSION['gvals']))
{
$_SESSION['gvals']=$rowgro[$Col_name];
}
else
{
$_SESSION['gvals']=$_SESSION['gvals'].",".$rowgro[$Col_name];
}
}
}
}  
   if(isset($_POST['groupback']))
  {
	  $sele_groupby=explode("_",$_SESSION['sele_groupby']);
	 $_SESSION['back_groupby']=$_SESSION['back_groupby']+1;
	  $gval=explode(",",$_SESSION['gvals']);
  $Column_names=explode(",",$_SESSION['Column_name']);
  $Columns="";
$Vals="";
  for($b=0;$b<count($Column_names)-1;$b++)
  { 
   if(empty($Vals))
  {
  $Vals=$gval[$b];
  }
  else
  {
  $Vals=$Vals.",".$gval[$b];
  }
   if(empty($Columns))
  {
  $Columns=$Column_names[$b];
  }
  else
  {
  $Columns=$Columns.",".$Column_names[$b];
  }
  }
  $_SESSION['gvals']=$Vals;
$_SESSION['Column_name']=$Columns;
	
  $gval=explode(",",$_SESSION['gvals']);
  $Column_names=explode(",",$_SESSION['Column_name']);
    if($_SESSION['Access_Type']=="Administrator")
  {
   if($_SESSION['Column_name']=="")
  {
   $res_que="SELECT * FROM teacher";
  }
  else
  {
   $res_que="SELECT * FROM teacher WHERE ";
   for($j=0;$j<count($Column_names);$j++)
  {
  $Col_name=$Column_names[$j];
   $res_que=$res_que.$Col_name."='".$gval[$j]."'";
   if($j!=(count($Column_names)-1))
  {
  $res_que=$res_que." AND ";
  }
  }
  }
    $resultgro=mysql_query($res_que);
	$Exc_que=$res_que;
   $number_of_rows=mysql_num_rows($resultgro);
    }
 else if($_SESSION['Access_Type']=="Teacher in Charge"||$_SESSION['Access_Type']=="Teacher")
  {
   $NIC_Number=$_SESSION['NIC_Number'];
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
   }
    if($_SESSION['Column_name']=="")
  {
   $res_que="SELECT * FROM teacher WHERE School_Id='".$Own_School_Id."'";
  }
  else
  {
   $res_que="SELECT * FROM teacher WHERE ";
   for($j=0;$j<count($Column_names);$j++)
  {
  $Col_name=$Column_names[$j];
    $res_que=$res_que.$Col_name."='".$gval[$j]."'";
   if($j!=(count($Column_names)-1))
  {
  $res_que=$res_que." AND ";
  }
  if($j==(count($Column_names)-1))
  {
  $res_que=$res_que." AND School_Id='".$Own_School_Id."'";
  }
  }
  }
     $resultgro=mysql_query($res_que);
	$Exc_que=$res_que;
   $number_of_rows=mysql_num_rows($resultgro);
     }
  }
    if(isset($_POST['dele']))
  {
   $action="delete";
   }
   ?>
<?php
include_once "../header2.php";
?>
<?php
include_once "topmenu.php";
?>
<div id="content">
	<div id="main">
	  <div id="bodyfield">
<br/>
<?php
if($action=="delete")
{
$dvari=$_POST['Verifi'];
if($dvari!="")
{
$vari=explode(",",$dvari);
$T_NIC_Number=$vari['0'];
}
if($dvari!="")
{
if($_SESSION['Access_Type']=="Administrator")
{
$resultdel=mysql_query("DELETE FROM teacher WHERE T_NIC_Number='$T_NIC_Number'");
if($resultdel)
{
$_SESSION['del']="Successfully deleted!";
 if($resulttra)
   {
		  while($rowtra=mysql_fetch_array($resulttra))
		 {
		 	$Training_Id=$rowtra['Training_Id'];
		mysql_query("DELETE FROM training_details WHERE T_NIC_Number='$T_NIC_Number' AND Training_Id='$Training_Id'");
		 }
		 }
		 	 if($resultres)
   {
		 while($rowres=mysql_fetch_array($resultres))
		 {
	    $Training_Id=$rowres['Training_Id'];
		mysql_query("DELETE FROM resource_team WHERE T_NIC_Number='$T_NIC_Number' AND Training_Id='$Training_Id'");
		 }
		 }
 		  if(mysql_num_rows(mysql_query("SELECT * FROM training_details WHERE Teacher_NIC='$T_NIC_Number'"))!=0)
	  {
$_SESSION['del']=$_SESSION['del']." ,unable to delete this record from training details!";
  }
  
  if(mysql_num_rows(mysql_query("SELECT * FROM resource_team WHERE T_NIC_Number='$T_NIC_Number'"))!=0)
	  {
 $_SESSION['del']=$_SESSION['del']." ,unable to delete this record from resource team!";
   }
}
if(!$resultdel)
{
$_SESSION['del']="Sorry unable to delete this!";
}
}
else if($_SESSION['Access_Type']=="Teacher in Charge")
{
$result=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$T_NIC_Number'");
$resulttra=mysql_query("SELECT * FROM training_details WHERE T_NIC_Number='$T_NIC_Number'");
$resultres=mysql_query("SELECT * FROM resource_team WHERE T_NIC_Number='$T_NIC_Number'");
$Accessed_By=$_SESSION['NIC_Number'];
   date_default_timezone_set("Europe/Paris");
    $t_d=date("Y-m-d");
   if($row=mysql_fetch_array($result))
   {
   $Role=$row['Role'];
   $T_NIC_Number=$row['T_NIC_Number'];
	$School_Id=$row['School_Id'];
	$First_Name=$row['First_Name'];
	$Last_Name=$row['Last_Name'];
	$Date_Of_Birth=$row['Date_Of_Birth'];
  $Gender=$row['Gender'];
  $Nature_Of_Appointment=$row['Nature_Of_Appointment'];
  $Service=$row['Service'];
  $A_Qua=$row['Acadamic_Qualifications'];
  $Profe_Qualifications=$row['Professional_Qualifications'];
  $Achieve=$row['Achievements_Awards'];
  $Address=$row['Address'];
  $Mobile_Tp_Number=$row['Mobile_Tp_Number'];
  $Home_Tp_Number=$row['Home_Tp_Number'];
  $Office_Tp_Number=$row['Office_Tp_Number'];
  $Appointment_Date=$row['Appointment_Date'];
  $Appointed_Subject=$row['Appointed_Subject'];
   $Last_Updated_Date=$row['Last_Updated_Date'];  
   $A_Qua=$row['Academic_Qualifications'];  
   $Specialised_In=$row['Specialised_In'];
   }
   if($resulttra)
   {
    while($rowtra=mysql_fetch_array($resulttra))
		 {
		 if(empty($Training_Id))
		 {
		 $Training_Id=$rowtra['Training_Id'];
		 }
		 else
		 {
		  $Training_Id=$Training_Id.",".$rowtra['Training_Id'];
		 }
		  if(empty($Duration))
		 {
		 $Duration=$rowtra['Duration'];
		 }
		 else
		 {
		  $Duration=$Duration.",".$rowtra['Duration'];
		 }
		 }
		 }
		 if($resultres)
   {
		 while($rowres=mysql_fetch_array($resultres))
		 {
		  if(empty($From_Date))
		 {
		 $From_Date=$rowtra['From_Date'];
		 }
		 else
		 {
		  $From_Date=$From_Date.",".$rowtra['From_Date'];
		 }
		 $Member_Id=$rowres['Member_Id'];
		 }
		 }
  $sql=mysql_query("INSERT INTO deleted_teacher(Specialised_In,Role,T_NIC_Number,School_Id,First_Name,Last_Name,Date_Of_Birth,Gender,Nature_Of_Appointment,Academic_Qualifications,Professional_Qualifications,Achievements_Awards,Service,Address,Mobile_Tp_Number,Home_Tp_Number,Office_Tp_Number,Appointment_Date,Appointed_Subject,Deleted_date,Accessed_By,Last_Updated_Date,Training_Id,Duration,Member_Id,From_Date) VALUES('$Specialised_In','$Role','$T_NIC_Number','$School_Id','$First_Name','$Last_Name','$Date_Of_Birth','$Gender','$Nature_Of_Appointment','$A_Qua','$Profe_Qualifications','$Achieve','$Service','$Address','$Mobile_Tp_Number','$Home_Tp_Number','$Office_Tp_Number','$Appointment_Date','$Appointed_Subject','$t_d','$Accessed_By','$Last_Updated_Date','$Training_Id','$Duration','$Member_Id','$From_Date')");
if($sql)
{
		$del=mysql_query("DELETE FROM teacher WHERE T_NIC_Number='$T_NIC_Number'");
	if($del)
  {
$_SESSION['del']="This record is successfully deleted!"; 
 if($resulttra)
   {
		  while($rowtra=mysql_fetch_array($resulttra))
		 {
		 	$Training_Id=$rowtra['Training_Id'];
		mysql_query("DELETE FROM training_details WHERE T_NIC_Number='$T_NIC_Number' AND Training_Id='$Training_Id'");
		 }
		 }
		 	 if($resultres)
   {
		 while($rowres=mysql_fetch_array($resultres))
		 {
	    $Training_Id=$rowres['Training_Id'];
		mysql_query("DELETE FROM resource_team WHERE T_NIC_Number='$T_NIC_Number' AND Training_Id='$Training_Id'");
		 }
		 }
 	  if(mysql_num_rows(mysql_query("SELECT * FROM training_details WHERE Teacher_NIC='$T_NIC_Number'"))!=0)
	  {
$_SESSION['del']=$_SESSION['del']." ,unable to delete this record from training details!";
  }
  
  if(mysql_num_rows(mysql_query("SELECT * FROM resource_team WHERE T_NIC_Number='$T_NIC_Number'"))!=0)
	  {
 $_SESSION['del']=$_SESSION['del']." ,unable to delete this record from resource team!";
   }
  }
if(!$del)
  {
 $_SESSION['del']="Sorry unable to delete this record!";
 mysql_query("DELETE FROM deleted_teacher WHERE T_NIC_Number='$T_NIC_Number' AND Deleted_Date='$t_d'");
  }	  
  }
  if(!$sql)
{
 $_SESSION['del']="Sorry unable to delete this record!";
 }
}
}
}
echo '<form  action="#" method="POST">';
echo "<input type='hidden' size='1' id='Verifi' name='Verifi'/>";
echo '<br/>';


if($_GET['action']=="edit"&&$action!="delete"&&$action!="group"&&!isset($_POST['groupback'])&&$_SESSION['Access_Type']!="Teacher")
{
$T_NIC_Number=$_GET['T_NIC_Number'];
$result=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$T_NIC_Number'");
if($result)
   {
$qucol="SHOW COLUMNS FROM teacher";
$resultcol=mysql_query($qucol);
$totcol=mysql_num_rows($resultcol);
while($rowcolu=mysql_fetch_row($resultcol))
{
if(empty($colnamearray))
{
$colnamearray=$rowcolu[0];
}
else
{
$colnamearray=$colnamearray.",".$rowcolu[0];
}
}
	$cnamearray=explode(",",$colnamearray);
	     if(!isset($_POST['Go']))
	 {	 
	 echo '<table class="tablefontv">';
	if($row=mysql_fetch_array($result))
  {
 $cnamearray=explode(',',$colnamearray);
    for($cv=0;$cv<count($cnamearray);$cv++)
	{
	$val=$cnamearray[$cv];
	  $th_cname= str_replace("_"," ",$val);
		$valu=$row[$val];
		if($val!="Last_Updated_Date")
		{
    echo '<tr>';
        echo '<th width="200" height="29" scope="row" bgcolor="#3399CC">';
		echo $th_cname.":";
		echo '</th>';
        echo '<td width="144">';
		if($th_cname=="Specialised In")
		{
		$Spec_In=mysql_query("SELECT DISTINCT(Specialised_In) FROM teacher");	  
  while($row=mysql_fetch_array($Spec_In))
  {
$Spe_In=$row['Specialised_In'];
$splited_spe_In=explode(",",$Spe_In);
$All_Specia_In=explode(",",$Specia_In);
for($sp=0;$sp<count($splited_spe_In);$sp++)
{
$s_exists="";
for($spa=0;$spa<count($All_Specia_In);$spa++)
{
if($splited_spe_In[$sp]==$All_Specia_In[$spa])
{
$s_exists="yes";
break;
}
}
if($s_exists=="")
{
if(empty($Specia_In))
{
 $Specia_In=$splited_spe_In[$sp];
}
else
{
 $Specia_In=$Specia_In.",".$splited_spe_In[$sp];
}
}
}
}
	$allSpecia_In=explode(",",$Specia_In);
	$regSpecia_In=explode(",",$valu);
	for($s=0;$s<count($allSpecia_In);$s++)
{ 
$Spe_exists="";  
for($i=0;$i<count($regSpecia_In);$i++)
{		  
if($allSpecia_In[$s]==$regSpecia_In[$i])
{
$Spe_exists="yes";
  echo "<input type='checkbox' name='Specialised_In[]' value='$allSpecia_In[$s]' checked='checked'/>";
  echo $allSpecia_In[$s].'</br>';
  }
  }
  if($Spe_exists=="")
  {
  echo "<input type='checkbox' name='Specialised_In[]' value='$allSpecia_In[$s]'/>";
  echo $allSpecia_In[$s].'</br>';
  }
  }
  echo "<font color='red'>or</font> New";
  echo "<input type='text' name='New_Specialised_In' value='$New_Specialised_In'";
		}
		else if($th_cname=="Gender")
		{
		if($valu=="Male")
	  {
	    echo '<input type="radio" name="Gender" value="Male" id="Gender_0" checked="checked" />';
	   echo "Male";
	  }
	  else
	  {
		  echo '<input type="radio" name="Gender" value="Male" id="Gender_0" />';
	   echo "Male";
	  }
	  	 echo '<br />';
        if($valu=="Female")
		{
          echo '<input type="radio" name="Gender" value="Female" id="Gender_1" checked="checked" />';
          echo "Female";
  }
  else
  {
	   echo '<input type="radio" name="Gender" value="Female" id="Gender_1" />';
          echo "Female";
  }
		}
		else if($th_cname=="Academic Qualifications")
		{
		if($valu!="")
{
$acQua= explode(",",$valu);
 $ol="";
 $oac="";
$al="";
for($i=0;$i<count($acQua);$i++)
{
if($acQua[$i]=='O/Level')
{$ol="Yes";
echo "<input type='checkbox' name='Acadamic_Qualifications[]' value='O/Level' checked='checked'/>";
  echo "O/Level";
  echo "<br/>";
  }
  if($acQua[$i]=='A/Level')
  {$al="Yes";
  echo "<input type='checkbox' name='Acadamic_Qualifications[]' value='A/Level' checked='checked'/>";
 echo "A/Level";
 echo "<br/>";
 }
 if($acQua[$i]!='A/Level'&&$acQua[$i]!='O/Level'&&$acQua[$i]!="")
  {
  $oac="Yes";
   $ac=substr($acQua[$i],4);
echo "<input type='checkbox' name='Acadamic_Qualifications[]' value='Degree_holder' checked='checked'/>";
echo "Degree holder,Subjects:";
echo '<br/>';
?>
<textarea name='Acadamic_Qualifications_Deg'><?php echo $ac." "; ?></textarea>
<?php
}
 }
if($ol=="")
  {
echo "<input type='checkbox' name='Acadamic_Qualifications[]' value='O/Level'/>";
  echo "O/Level";
   echo "<br/>";
  }
 if($al=="")
  {
  echo "<input type='checkbox' name='Acadamic_Qualifications[]' value='A/Level'/>";
 echo "A/Level";
  echo "<br/>";
 }
if($oac=="")
 {
echo "<input type='checkbox' name='Acadamic_Qualifications[]' value='Degree_holder'/>";
echo "Degree holder,Subjects:";
echo '<br/>';
echo "<textarea name='Acadamic_Qualifications_Deg'></textarea>";
 echo "<br/>";
}
}
else
{
echo "<input type='checkbox' name='Acadamic_Qualifications[]' value='O/Level'/>";
  echo "O/Level";
 echo "<input type='checkbox' name='Acadamic_Qualifications[]' value='A/Level'/>";
 echo "A/Level";
echo "<input type='checkbox' name='Acadamic_Qualifications[]' value='Degree_holder'/>";
echo "Degree holder,Subjects:";
echo '<br/>';
echo "<textarea name='Acadamic_Qualifications_Deg'></textarea>";
}
}
		else if($th_cname=="Professional Qualifications")
		{
		?>
		<textarea name="Professional_Qualifications">
	  <?php
{
echo str_replace("deg_"," ",$valu); 
}?>
      </textarea>
	  <?php
		}
		else if($th_cname=="Date Of Birth")
		{
		if(isset($valu))
		{
		echo "<input type='text' name='$val' value='$valu' class='inputDate' id='inputDate'>";
		}
		else
		{
		echo "<input type='text' name='$val' value='$t_d' class='inputDate' id='inputDate'>";
		}
		}
		else if($th_cname=="Appointment Date")
		{
		if(isset($valu))
		{
		echo "<input type='text' name='$val' value='$valu' class='inputDate1' id='inputDate1'>";
		}
		else
		{
		echo "<input type='text' name='$val' value='$t_d' class='inputDate1' id='inputDate1'>";
		}
		}
		else
		{
		echo "<input type='text' name='$val' value='$valu'>";
		}
		echo '</td>';
      echo '</tr>';
	}
}
}	 
	 echo '</table>';
	  echo '<br/>';
	   echo '<input name="Go" align="middle" type="submit" value="Go" class="gobutton"/>';	
	   }
	   if(isset($_POST['Go']))
	   {
	$T_NIC_Number1=$_POST['T_NIC_Number'];
   $School_Id=$_POST['School_Id'];
   $First_Name=$_POST['First_Name'];
  $Last_Name=$_POST['Last_Name'];
   $Date_Of_Birth=$_POST['Date_Of_Birth'];
   $Gender=$_POST['Gender'];
   $Nature_Of_Appointment=$_POST['Nature_Of_Appointment'];
   $Service=$_POST['Service'];
   $Specialised_In=$_POST['Specialised_In'];
   $New_Specialised_In=$_POST['New_Specialised_In'];
 $reg_Specia_In="";
 for($i=0;$i<sizeof($Specialised_In);$i++)
  {
  if(empty($reg_Specia_In))
  {
  $reg_Specia_In=$Specialised_In[$i];
  }
  else
  {
  $reg_Specia_In=$reg_Specia_In.",".$Specialised_In[$i];
  }
  }
  if($New_Specialised_In!="")
  {
  if(empty($reg_Specia_In))
  {
  $reg_Specia_In=$New_Specialised_In;
  }
  else
  {
  $reg_Specia_In=$reg_Specia_In.",".$New_Specialised_In;
  }
  }
  if(empty($reg_Specia_In))
  {
  $reg_Specia_In="";
  }
if($Service=="")
{
$serv="0year";
}
if($Service!="")
{
$chars = str_split( $Service );
  $i=0;
while($i<strlen($Service))
{
$c=$chars[$i]; 
if($c=="y"||$c=="Y")
{
$st=$i;
break;
}
else
{
$i++;
}
}
if($st>0&&$st<strlen($Service))
{
$ser=substr($Service,0,$st);
}
if($st==0)
{
$ser="0";
}
if($st=="")
{
$ser=$Service;
}
if((int) $ser>1)
{
$serv=$ser."years";
}
if((int) $ser<=1)
{
$serv=$ser."year";
}
}
  $Acadamic_Qualifications=$_POST['Acadamic_Qualifications'];
  $Professional_Qualifications=$_POST['Professional_Qualifications'];
	 $Profe_Qualifications= mysql_real_escape_string($Professional_Qualifications);
  $Achievements=$_POST['Achievements_Awards'];
  $Achieve= mysql_real_escape_string($Achievements);
 $Address=$_POST['Address'];
 $Role=$_POST['Role'];
  $Mobile_Tp_Number=$_POST['Mobile_Tp_Number'];
   $Home_Tp_Number=$_POST['Home_Tp_Number'];
   $Office_Tp_Number=$_POST['Office_Tp_Number'];
  $Appointment_Date=$_POST['Appointment_Date'];
 $Appointed_Subject=$_POST['Appointed_Subject'];
    $dehol="";
	date_default_timezone_set("Europe/Paris");
    $t_d=date("Y/m/d");
	$A_Qua="";
for($i=0;$i<sizeof($Acadamic_Qualifications);$i++)
  {
   if($Acadamic_Qualifications[$i]=="Degree_holder")
  {
 $dehol="yes";
  $deg=$_POST['Acadamic_Qualifications_Deg'];
   $degree=mysql_real_escape_string($deg);
    if($degree=="")
  {
  $_SESSION['errordeg']="Please type your subject you got degree on it!";
  }
  else
  {
  if(empty($A_Qua))
  {
  $A_Qua="deg_".$degree;
  }
  else
  {
  $A_Qua=$A_Qua.",deg_".$degree;
  }
  }
  }
  else
  {
  if(empty($A_Qua))
  {
  $A_Qua=$Acadamic_Qualifications[$i];
  }
  else
  {
$A_Qua=$A_Qua.','.$Acadamic_Qualifications[$i];
}
}
}
if($T_NIC_Number1!=""&&$School_Id!=""&&$First_Name!=""&&$Last_Name!=""&&$Date_Of_Birth!=""&&$Gender!=""&&$Nature_Of_Appointment!=""&&$Service!=""&&$Academic_Qualifications!=""&&$Address!=""&&$Appointment_Date!=""&&$Appointed_Subject!="")
	{
if($dehol=="yes")
  {
  $deg=$_POST['Acadamic_Qualifications_Deg'];
   $degree=mysql_real_escape_string($deg);
    if($degree!="")
  {
  $up=mysql_query("UPDATE teacher SET Specialised_In='$reg_Specia_In',Role='$Role',T_NIC_Number='$T_NIC_Number1',School_Id='$School_Id',First_Name='$First_Name',Last_Name='$Last_Name',Date_Of_Birth='$Date_Of_Birth',Gender='$Gender',Nature_Of_Appointment='$Nature_Of_Appointment',Service='$serv',Academic_Qualifications='$A_Qua',Professional_Qualifications='$Profe_Qualifications',Address='$Address',Mobile_Tp_Number='$Mobile_Tp_Number',Home_Tp_Number='$Home_Tp_Number',Office_Tp_Number='$Office_Tp_Number',Appointment_Date='$Appointment_Date',Appointed_Subject='$Appointed_Subject',Last_Updated_Date='$t_d',Achievements_Awards='$Achieve' WHERE T_NIC_Number='$T_NIC_Number'");
if(!$up)
	   {
	   $_SESSION['up']="Sorry unable to edit this please try again!";
	   }
	}
}
else
	{
$up=mysql_query("UPDATE teacher SET Specialised_In='$reg_Specia_In',Role='$Role',T_NIC_Number='$T_NIC_Number1',School_Id='$School_Id',First_Name='$First_Name',Last_Name='$Last_Name',Date_Of_Birth='$Date_Of_Birth',Gender='$Gender',Nature_Of_Appointment='$Nature_Of_Appointment',Service='$serv',Academic_Qualifications='$A_Qua',Professional_Qualifications='$Profe_Qualifications',Address='$Address',Mobile_Tp_Number='$Mobile_Tp_Number',Home_Tp_Number='$Home_Tp_Number',Office_Tp_Number='$Office_Tp_Number',Appointment_Date='$Appointment_Date',Appointed_Subject='$Appointed_Subject',Last_Updated_Date='$t_d',Achievements_Awards='$Achieve' WHERE T_NIC_Number='$T_NIC_Number'");
	   	   if(!$up)
	   {
	   $_SESSION['up']="Sorry unable to edit this please try again!";
	   }
	  } 
	  }
	if($_SESSION['Access_Type']=="Teacher"||$_SESSION['Access_Type']=="Teacher in Charge")
	{
	$T_NIC_Number=$_GET['T_NIC_Number'];
	$NIC_Number=$_SESSION['NIC_Number'];
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
   $result=mysql_query("SELECT * FROM teacher WHERE School_Id='$Own_School_Id'");
   $Exc_que="SELECT * FROM teacher WHERE School_Id='$Own_School_Id'";
   $number_of_rows=mysql_num_rows($result);
  }
  }
	else if($_SESSION['Access_Type']=="Administrator")
	{
	   	   $result=mysql_query("SELECT * FROM teacher");
   $Exc_que="SELECT * FROM teacher";
   $number_of_rows=mysql_num_rows($result);
	}
if(mysql_num_rows($result)!=0)
   {
   $rnum=0;
if(mysql_num_rows($result)>10)
  {
  echo '<div style="width:115%; height:500px; overflow-x:scroll; overflow-y:scroll;">';
  }
  else
  {
echo '<div style="width:115%; overflow-x:scroll;">';
}
  echo '<table width="1800" border="1" class="tablefontv">';
  	if($result)
  {
echo '<tr bgcolor="#6AB5FF">';
		if($_SESSION['Access_Type']=="Administrator"||($_SESSION['Access_Type']=="Teacher in Charge"&&$Own_School_Id!=""))
	{
echo '<td width="39"></td>
<td width="39"></td>';
}
$cnamearray=explode(',',$colnamearray);
    for($cv=0;$cv<count($cnamearray);$cv++)
	{
	$val=$cnamearray[$cv];
	  $th_cname= str_replace("_"," ",$val);
		
	$valu=$row[$val];
         echo '<td>';
		if($val=="School_Id")
  {
    $cnu=$cv+1;
	echo "(".$cnu.")School Name";
  }
  else
  {
	$cnu=$cv+1;
	echo "(".$cnu.")".$th_cname;
  }
		echo '</td>';
    }
		
		echo '<td>Column No</td>';
	echo '</tr>';
}

  while($row=mysql_fetch_array($result))
  {
	  $rnum=$rnum+1;  
$n=$row['T_NIC_Number'];
$name=$n;
?>
</form>
   <tr bgcolor="#999999">
   <?php echo "<form action='#' method='post'>";
   	if($_SESSION['Access_Type']=="Administrator"||($_SESSION['Access_Type']=="Teacher in Charge"&&$Own_School_Id!=""))
	{	?>
<td width="39">
<a href='?action=edit&T_NIC_Number=<?php echo $n; ?>'><img src="../images/edit.png"/></a></td>
<td width="39"><?php echo "<input type='submit' id='$name' name='dele' onclick='DeleteVerification($rnum,this.id)' class='submitdelete' value=''/>";?></td>
	<?php 
	}
$cnamearray=explode(',',$colnamearray);
	for($cv=0;$cv<count($cnamearray);$cv++)
	{
	$val=$cnamearray[$cv];
	  $th_cname= str_replace("_"," ",$val);
		
	$valu=$row[$val];
       echo '<td>';
	   	if($val=="School_Id")
  {
  $get_Sch_name=mysql_query("SELECT * FROM school WHERE School_Id='".$valu."'");
if($rs=mysql_fetch_array($get_Sch_name))
{
echo $Name=$rs['Name'];
}
else
{
echo '';
}
  }
  else
  {
		echo str_replace("deg_"," ",$valu);
		}
		echo '</td>';
  
	}
	
	?>
	<td width="90">
    <?php
	 if($_SESSION['Access_Type']=="Teacher"||$_SESSION['Access_Type']=="Teacher in Charge")
	{
	$NIC_Number=$_SESSION['NIC_Number'];
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
	   $resultte=mysql_query("SELECT * FROM teacher WHERE School_Id='$Own_School_Id'");
   $Exc_que="SELECT * FROM teacher WHERE School_Id='$Own_School_Id'";
   $number_of_rows=mysql_num_rows($resultte);
	      if($resultte)
  {
  if(mysql_num_rows($resultte)!=0)
  {
  $_SESSION['errornotallo']="Sorry you are not allowed to view all details!";
  }
  }
  }
  $n=mysql_num_rows($resultte);
	}
	else if($_SESSION['Access_Type']=="Administrator")
	{
		$resultte=mysql_query("SELECT * FROM teacher");
   $Exc_que="SELECT * FROM teacher";
   $number_of_rows=mysql_num_rows($resultte);
  $n=mysql_num_rows($resultte);
	}
    echo "<div class='ctxt'><input type='text' size='5' name='$name' id='$groupcolumn'  onkeyup='GetCol(this.value,this.name,$rnum)' onclick='GetTBox($rnum,$n)'/></div>";
	$button="button".$rnum;
		echo "<div id='$button' class='sub_but'></div>";
	?></td>
    <?php
  echo '</tr>';
  }
  
   echo "</table>";
   echo '</div>';
     $Column_names=explode(",",$_SESSION['Column_name']);
   if(count($Column_names)>0&&$_SESSION['Column_name']!="")
  {
   ?>
   <br/>
   <form action="#"/>
   <input type="submit" name="groupback" class="groupback" value=""/></form>
   <?php
   }
  echo "</form>";
}
	   }
	}
	}
		else
	{
	if(isset($_POST['groupback']))
  {
     $rnum=0;
	if($resultgro)
	 {	  
$qucol="SHOW COLUMNS FROM teacher";
$resultcol=mysql_query($qucol);
$totcol=mysql_num_rows($resultcol);
while($rowcolu=mysql_fetch_row($resultcol))
{
if(empty($colnamearray))
{
$colnamearray=$rowcolu[0];
}
else
{
$colnamearray=$colnamearray.",".$rowcolu[0];
}

}
if(mysql_num_rows($resultgro)>10)
  {
  echo '<div style="width:115%; height:500px; overflow-x:scroll; overflow-y:scroll;">';
  }
  else
  {
echo '<div style="width:115%; overflow-x:scroll;">';
}
  echo '<table width="1800" border="1" class="tablefontv">';
  echo '<tr bgcolor="#6AB5FF">';
		if($_SESSION['Access_Type']=="Administrator"||($_SESSION['Access_Type']=="Teacher in Charge"&&$Own_School_Id!=""))
	{
echo '<td width="39"></td>
<td width="39"></td>';
}
$cnamearray=explode(',',$colnamearray);
     for($cv=0;$cv<count($cnamearray);$cv++)
	{
	$val=$cnamearray[$cv];
	  $th_cname= str_replace("_"," ",$val);
		
	$valu=$row[$val];
        echo '<td>';
		if($val=="School_Id")
  {
    $cnu=$cv+1;
	echo "(".$cnu.")School Name";
  }
  else
  {
	$cnu=$cv+1;
	echo "(".$cnu.")".$th_cname;
  }
		echo '</td>';
   
	}
	echo '<td>Column No</td>';
	echo '</tr>';
while($row=mysql_fetch_array($resultgro))
  {$rnum=$rnum+1;
    $n=$row['T_NIC_Number'];
$name=$n;
?>
<tr bgcolor="#999999"><?php echo "<form action='#' method='post'>";
   	if($_SESSION['Access_Type']=="Administrator"||($_SESSION['Access_Type']=="Teacher in Charge"&&$Own_School_Id!=""))
	{	?>
<td width="39">
<a href='?action=edit&T_NIC_Number=<?php echo $n; ?>'><img src="../images/edit.png"/></a></td>
<td width="39"><?php echo "<input type='submit' id='$name' name='dele' onclick='DeleteVerification($rnum,this.id)' class='submitdelete' value=''/>";?></td>
	<?php 
	}
	$cnamearray=explode(',',$colnamearray);
	for($cv=0;$cv<count($cnamearray);$cv++)
	{
	$val=$cnamearray[$cv];
	  $th_cname= str_replace("_"," ",$val);
		
	$valu=$row[$val];
        echo '<td>';
		   	if($val=="School_Id")
  {
  $get_Sch_name=mysql_query("SELECT * FROM school WHERE School_Id='".$valu."'");
if($rs=mysql_fetch_array($get_Sch_name))
{
echo $Name=$rs['Name'];
}
else
{
echo '';
}
  }
  else
  {
		echo str_replace("deg_"," ",$valu);
		}
		echo '</td>';
   
	}
	?>
	<td width="90">
	<?php
	if($_SESSION['Access_Type']=="Administrator")
	{
		$resultte=mysql_query("SELECT * FROM teacher");
  $n=mysql_num_rows($resultte);
	}
	else if($_SESSION['Access_Type']=="Teacher"||$_SESSION['Access_Type']=="Teacher in Charge")
	{
	 $NIC_Number=$_SESSION['NIC_Number'];
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
	   $resultte=mysql_query("SELECT * FROM teacher WHERE School_Id='$Own_School_Id'");
   $Exc_que="SELECT * FROM teacher WHERE School_Id='$Own_School_Id'";
   $number_of_rows=mysql_num_rows($resultte);
	      if($resultte)
  {
  if(mysql_num_rows($resultte)!=0)
  {
  $_SESSION['errornotallo']="Sorry you are not allowed to view all details!";
  }
  }
  $n=mysql_num_rows($resultte);
	}
	}
    echo "<div class='ctxt'><input type='text' size='5' name='$name' id='$groupcolumn'  onkeyup='GetCol(this.value,this.name,$rnum)' onclick='GetTBox($rnum,$n)'/></div>";
	$button="button".$rnum;
		echo "<div id='$button' class='sub_but'></div>";
	?></td>
    <?php
  echo '</tr>';
  }
  }
   echo "</table>";
   echo '</div>';
   $Column_names=explode(",",$_SESSION['Column_name']);
   if(count($Column_names)>0&&$_SESSION['Column_name']!="")
  {
    ?>
   <br/>   
   <form action="#"/>
   <input type="submit" name="groupback" class="groupback" value=""/></form>
   <?php
   }
   ?>
   </form>
<?php   
   }
   if(!isset($_POST['groupback']))
  {
	  if($_SESSION['Access_Type']=="Administrator")
{
$result=mysql_query("SELECT * FROM teacher");
   $Exc_que="SELECT * FROM teacher";
   $number_of_rows=mysql_num_rows($result);
}
else if($_SESSION['Access_Type']=="Teacher"||$_SESSION['Access_Type']=="Teacher in Charge")
	{
	 $NIC_Number=$_SESSION['NIC_Number'];
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
   $result=mysql_query("SELECT * FROM teacher WHERE School_Id='$Own_School_Id'");
   $Exc_que="SELECT * FROM teacher WHERE School_Id='$Own_School_Id'";
   $number_of_rows=mysql_num_rows($result);
     }
   else
   {
   $_SESSION['errornorow']="Sorry there is no result to view!";
   }
    }
if($result)
   {
    if(mysql_num_rows($result)==0)
   {
   $_SESSION['errornorow']="Sorry there is no result to view!";
   }
   if(mysql_num_rows($result)>0)
   {
   $rnum=0;
$qucol="SHOW COLUMNS FROM teacher";
$resultcol=mysql_query($qucol);
$totcol=mysql_num_rows($resultcol);
while($rowcolu=mysql_fetch_row($resultcol))
{
if(empty($colnamearray))
{
$colnamearray=$rowcolu[0];
}
else
{
$colnamearray=$colnamearray.",".$rowcolu[0];
}
}

 if($action!="group")
  {  
  if(mysql_num_rows($result)>10)
  {
  echo '<div style="width:115%; height:500px; overflow-x:scroll; overflow-y:scroll;">';
  }
  else
  {
  echo '<div style="width:115%; overflow-x:scroll;">';
  }
  echo '<table width="1800" border="1" class="tablefontv">';
  	if($result)
  {
echo '<tr bgcolor="#6AB5FF">';
  if($_SESSION['Access_Type']=="Administrator")
{
echo '<td width="39"></td>
<td width="39"></td>';
	}
  if($_SESSION['Access_Type']=="Teacher in Charge")
{
if($Own_School_Id!="")
{	
echo '<td width="39"></td>
<td width="39"></td>';
	}
	}
	
if($_SESSION['Access_Type']=="Administrator")
{
$cnamearray=explode(',',$colnamearray);
     for($cv=0;$cv<count($cnamearray);$cv++)
	{
	 $val=$cnamearray[$cv];
	  $th_cname= str_replace("_"," ",$val);
		
	$valu=$row[$val];
  echo '<td>';
		if($val=="School_Id")
  {
    $cnu=$cv+1;
	echo "(".$cnu.")School Name";
  }
  else
  {
	$cnu=$cv+1;
	echo "(".$cnu.")".$th_cname;
  }
		echo '</td>';
   
	}
	echo '<td>Column No</td>';
	echo '</tr>';
	}
if($_SESSION['Access_Type']=="Teacher in Charge"||$_SESSION['Access_Type']=="Teacher")
{
if($Own_School_Id!="")
{
$cnamearray=explode(',',$colnamearray);
     for($cv=0;$cv<count($cnamearray);$cv++)
	{
	 $val=$cnamearray[$cv];
	  $th_cname= str_replace("_"," ",$val);
		
	$valu=$row[$val];
  echo '<td>';
	if($val=="School_Id")
  {
    $cnu=$cv+1;
	echo "(".$cnu.")School Name";
  }
  else
  {
	$cnu=$cv+1;
	echo "(".$cnu.")".$th_cname;
  }
		echo '</td>';
   
	}
	echo '<td>Column No</td>';
	echo '</tr>';
	}
	}
  while($row=mysql_fetch_array($result))
  {
	  $rnum=$rnum+1;    
$n=$row['T_NIC_Number'];
$delVerification="delVerification".$rnum;
$name=$n;
?>
<tr bgcolor="#999999"><?php echo "<form action='#' method='post'>";
   	if($_SESSION['Access_Type']=="Administrator"||($_SESSION['Access_Type']=="Teacher in Charge"&&$Own_School_Id!=""))
	{	?>
<td width="39">
<a href='?action=edit&T_NIC_Number=<?php echo $n; ?>'><img src="../images/edit.png"/></a></td>
<td width="39"><?php echo "<input type='submit' id='$name' name='dele' onclick='DeleteVerification($rnum,this.id)' class='submitdelete' value=''/>";?></td>
	<?php 
	}
	$cnamearray=explode(',',$colnamearray);
	for($cv=0;$cv<count($cnamearray);$cv++)
	{
	$val=$cnamearray[$cv];
	  $th_cname= str_replace("_"," ",$val);
		
		$valu=$row[$val];
            echo '<td>';
			   	if($val=="School_Id")
  {
  $get_Sch_name=mysql_query("SELECT * FROM school WHERE School_Id='".$valu."'");
if($rs=mysql_fetch_array($get_Sch_name))
{
echo $Name=$rs['Name'];
}
else
{
echo '';
}
  }
  else
  {
		echo str_replace("deg_"," ",$valu);
		}
		echo '</td>';
    	}
	?>
	<td width="159"><?php
	 if($_SESSION['Access_Type']=="Teacher"||$_SESSION['Access_Type']=="Teacher in Charge")
	{
	 $NIC_Number=$_SESSION['NIC_Number'];
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
   $resultte=mysql_query("SELECT * FROM teacher WHERE School_Id='$Own_School_Id'");
   if($resultte)
  {
  if(mysql_num_rows($resultte)!=0)
  {
  $_SESSION['errornotallo']="Sorry you are not allowed to view all details!";
  }
  }
  $n=mysql_num_rows($resultte);
  }
	}
	else if($_SESSION['Access_Type']=="Administrator")
	{
		$resultte=mysql_query("SELECT * FROM teacher");
   $n=mysql_num_rows($resultte);
	}
    echo "<div class='ctxt'><input type='text' size='5' name='$name' id='$groupcolumn'  onkeyup='GetCol(this.value,this.name,$rnum)' onclick='GetTBox($rnum,$n)'/></div>";
	$button="button".$rnum;
		echo "<div id='$button' class='sub_but'></div>";
	?></td>
   <?php
  echo '</tr>';
  }
  }
   echo "</table>";
   echo '</div>';
  }
   if($action=="group")
  {
  $l_val=count($Column_names)-1;
 $gval=explode(",",$_SESSION['gvals']);
   $Column_names=explode(",",$_SESSION['Column_name']);
    $gval=explode(",",$_SESSION['gvals']);
  if($_SESSION['Access_Type']=="Administrator")
  {  
      $res_que="SELECT * FROM teacher WHERE ";
   for($j=0;$j<count($Column_names);$j++)
  {
  $Col_name=$Column_names[$j];
     $res_que=$res_que.$Col_name."='".$gval[$j]."'";
   if($j!=(count($Column_names)-1))
  {
  $res_que=$res_que." AND ";
  }
  }
	 $resultgro=mysql_query($res_que);
	$Exc_que=$res_que;
   $number_of_rows=mysql_num_rows($resultgro);
  }
 else if($_SESSION['Access_Type']=="Teacher in Charge"||$_SESSION['Access_Type']=="Teacher")
  {
   $NIC_Number=$_SESSION['NIC_Number'];
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
   }
      $res_que="SELECT * FROM teacher WHERE ";
   for($j=0;$j<count($Column_names);$j++)
  {
  $Col_name=$Column_names[$j];
   
  $res_que=$res_que.$Col_name."='".$gval[$j]."'";
  
  if($j!=(count($Column_names)-1))
  {
  $res_que=$res_que." AND ";
  }
  if($j==(count($Column_names)-1))
  {
  $res_que=$res_que." AND School_Id='".$Own_School_Id."'";
  }
  }
   $resultgro=mysql_query($res_que);
	$Exc_que=$res_que;
   $number_of_rows=mysql_num_rows($resultgro);
 }
 if(mysql_num_rows($resultgro)>=10)
   {
  echo '<div style="width:115%; height:410px; overflow-x:scroll; overflow-Y:scroll;">';
  }
  else
  {
  echo '<div style="width:115%; overflow-x:scroll;">';
  }
  echo '<table width="1800" border="1" class="tablefontv">';
 
  	if($gval[$l_val]!="")
  {
echo '<tr bgcolor="#6AB5FF">';
		if($_SESSION['Access_Type']=="Administrator"||($_SESSION['Access_Type']=="Teacher in Charge"&&$Own_School_Id!=""))
	{
echo '<td width="39"></td>
<td width="39"></td>';
}
$cnamearray=explode(',',$colnamearray);
     for($cv=0;$cv<count($cnamearray);$cv++)
	{
	 $val=$cnamearray[$cv];
	  $th_cname= str_replace("_"," ",$val);
		
	$valu=$row[$val];
  echo '<td>';
		if($val=="School_Id")
  {
    $cnu=$cv+1;
	echo "(".$cnu.")School Name";
  }
  else
  {
	$cnu=$cv+1;
	echo "(".$cnu.")".$th_cname;
  }
		echo '</td>';
   
	}
	echo '<td>Column No</td>';
	echo '</tr>';
  $Column_names=explode(",",$_SESSION['Column_name']);
    $gval=explode(",",$_SESSION['gvals']);
	if($_SESSION['Column_name']!="")
  {

   while($row=mysql_fetch_array($resultgro))
  {
$rnum=$rnum+1;    
$n=$row['T_NIC_Number'];
$name=$n;
?>
<tr bgcolor="#999999"><?php echo "<form action='#' method='post'>";
   	if($_SESSION['Access_Type']=="Administrator"||($_SESSION['Access_Type']=="Teacher in Charge"&&$Own_School_Id!=""))
	{	?>
<td width="39">
<a href='?action=edit&T_NIC_Number=<?php echo $n; ?>'><img src="../images/edit.png"/></a></td>
<td width="39"><?php echo "<input type='submit' id='$name' name='dele' onclick='DeleteVerification($rnum,this.id)' class='submitdelete' value=''/>";?></td>
	<?php 
	}
	$cnamearray=explode(',',$colnamearray);
	for($cv=0;$cv<count($cnamearray);$cv++)
	{
	$val=$cnamearray[$cv];
	  $th_cname= str_replace("_"," ",$val);
		
		$valu=$row[$val];
            echo '<td>';   	if($val=="School_Id")
  {
  $get_Sch_name=mysql_query("SELECT * FROM school WHERE School_Id='".$valu."'");
if($rs=mysql_fetch_array($get_Sch_name))
{
echo $Name=$rs['Name'];
}
else
{
echo '';
}
  }
  else
  {
		echo str_replace("deg_"," ",$valu);
		}
		echo '</td>';
   
	}
	?>
	<td width="90">
	<?php
	 if($_SESSION['Access_Type']=="Teacher in Charge"||$_SESSION['Access_Type']=="Teacher")
	{
	$NIC_Number=$_SESSION['NIC_Number'];
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
	   $resultte=mysql_query("SELECT * FROM teacher WHERE School_Id='$Own_School_Id'");
   if($resultte)
  {
  if(mysql_num_rows($resultte)!=0)
  {
  $_SESSION['errornotallo']="Sorry you are not allowed to view all details!";
  }
  }
  $n=mysql_num_rows($resultte);
	}
	}
	else if($_SESSION['Access_Type']=="Administrator")
	{
		$resultte=mysql_query("SELECT * FROM teacher");
   $n=mysql_num_rows($resultte);
	}
    echo "<div class='ctxt'><input type='text' size='5' name='$name' id='$groupcolumn'  onkeyup='GetCol(this.value,this.name,$rnum)' onclick='GetTBox($rnum,$n)'/></div>";
	$button="button".$rnum;
		echo "<div id='$button' class='sub_but'></div>";
	?></td>
  <?php
  echo '</tr>';
  }
  }
  else
  {
echo '<tr bgcolor="#6AB5FF">';
		if($_SESSION['Access_Type']=="Administrator"||($_SESSION['Access_Type']=="Teacher in Charge"&&$Own_School_Id!=""))
{
echo '<td width="39"></td>
<td width="39"></td>';
}
$cnamearray=explode(',',$colnamearray);
     for($cv=0;$cv<count($cnamearray);$cv++)
	{
	 $val=$cnamearray[$cv];
	  $th_cname= str_replace("_"," ",$val);
		
	$valu=$row[$val];
  echo '<td>';
		if($val=="School_Id")
  {
    $cnu=$cv+1;
	echo "(".$cnu.")School Name";
  }
  else
  {
	$cnu=$cv+1;
	echo "(".$cnu.")".$th_cname;
  }
		echo '</td>';
   
	}
	echo '<td>Column No</td>';
	echo '</tr>';
  while($row=mysql_fetch_array($result))
  {
	  $rnum=$rnum+1;
    
$n=$row['T_NIC_Number'];
$delVerification="delVerification".$rnum;
$name=$n;
?>
<tr bgcolor="#999999"><?php echo "<form action='#' method='post'>";
   	if($_SESSION['Access_Type']=="Administrator"||($_SESSION['Access_Type']=="Teacher in Charge"&&$Own_School_Id!=""))
	{	?>
<td width="39">
<a href='?action=edit&T_NIC_Number=<?php echo $n; ?>'><img src="../images/edit.png"/></a></td>
<td width="39"><?php echo "<input type='submit' id='$name' name='dele' onclick='DeleteVerification($rnum,this.id)' class='submitdelete' value=''/>";?></td>
	<?php 
	}
	$cnamearray=explode(',',$colnamearray);
	for($cv=0;$cv<count($cnamearray);$cv++)
	{
	$val=$cnamearray[$cv];
	  $th_cname= str_replace("_"," ",$val);
		
		$valu=$row[$val];
            echo '<td>';
			   	if($val=="School_Id")
  {
  $get_Sch_name=mysql_query("SELECT * FROM school WHERE School_Id='".$valu."'");
if($rs=mysql_fetch_array($get_Sch_name))
{
echo $Name=$rs['Name'];
}
else
{
echo '';
}
  }
  else
  {
		echo str_replace("deg_"," ",$valu);
		}
		echo '</td>';
    	}
	?>
	<td width="159"><?php
	 if($_SESSION['Access_Type']=="Teacher"||$_SESSION['Access_Type']=="Teacher in Charge")
	{
	 $NIC_Number=$_SESSION['NIC_Number'];
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
   $resultte=mysql_query("SELECT * FROM teacher WHERE School_Id='$Own_School_Id'");
   if($resultte)
  {
  if(mysql_num_rows($resultte)!=0)
  {
  $_SESSION['errornotallo']="Sorry you are not allowed to view all details!";
  }
  }
  $n=mysql_num_rows($resultte);
  }
	}
	else if($_SESSION['Access_Type']=="Administrator")
	{
		$resultte=mysql_query("SELECT * FROM teacher");
   $n=mysql_num_rows($resultte);
	}
    echo "<div class='ctxt'><input type='text' size='5' name='$name' id='$groupcolumn'  onkeyup='GetCol(this.value,this.name,$rnum)' onclick='GetTBox($rnum,$n)'/></div>";
	$button="button".$rnum;
		echo "<div id='$button' class='sub_but'></div>";
	?></td>
   <?php
  echo '</tr>';
  }
  }
  }
   echo "</table>";
   echo '</div>';
  }
   $Column_names=explode(",",$_SESSION['Column_name']);
   if(count($Column_names)>0&&$_SESSION['Column_name']!="")
  {
   ?>
   <br/>
   <form action="#"/>
   <input type="submit" name="groupback" class="groupback" value=""/></form>
   <?php
   }
   echo "</form>";
}
}
 else
	   {
	   $_SESSION['errornorow']="Sorry there is no result to view!";
	   }
	   }
  }
  if($_GET['action']!="edit"&&$action!="delete")
  {
   if($number_of_rows>0)
   {
  $Exc_quer=str_replace("'","@",$Exc_que);
echo "<form action='../exportreport.php' method='post'><input type='submit' name='ToExcel' class='print' value=''/><input type='hidden' value='$Exc_quer' name='query'/><input type='hidden' value='teacher' name='Exc_table_name'/></form>";
  }
  }
  ?>
<font class="err">
<?php
 if(isset($_SESSION['errornotallo']))
{
echo '<img src="../images/alert.jpg" width="12" height="12"/>';
echo $_SESSION['errornotallo'];
unset($_SESSION['errornotallo']);
}
if(isset($_SESSION['errornorow']))
{
echo '<img src="../images/alert.jpg" width="12" height="12"/>';
echo $_SESSION['errornorow'];
unset($_SESSION['errornorow']);
}
	if(isset($_SESSION['errordeg']))
{
echo '<img src="../images/alert.jpg" width="12" height="12"/>';
echo $_SESSION['errordeg'];
unset($_SESSION['errordeg']);
}
if(isset($_SESSION['value_empty']))
{
echo '<img src="../images/alert.jpg" width="12" height="12"/>';
echo $_SESSION['value_empty'];
unset($_SESSION['value_empty']);
}

if($action=="delete")
{
	if(isset($_SESSION['del']))
{
	
echo '<img src="../images/alert.jpg" width="12" height="12"/>';
echo $_SESSION['del'];
unset($_SESSION['del']);
}
	if(isset($_SESSION['errortd']))
{
echo '<img src="../images/alert.jpg" width="12" height="12"/>';
echo $_SESSION['errortd'];
unset($_SESSION['errortd']);
}
	if(isset($_SESSION['errorrt']))
{
echo '<img src="../images/alert.jpg" width="12" height="12"/>';
echo $_SESSION['errorrt'];
unset($_SESSION['errorrt']);
}
}
if(isset($_SESSION['groupbyempty']))
{
echo '<img src="../images/alert.jpg" width="12" height="12"/>';
echo $_SESSION['groupbyempty'];
unset($_SESSION['groupbyempty']);
}
	if(isset($_POST['Go']))
	 {
	if(isset($_SESSION['up']))
{
echo '<img src="../images/alert.jpg" width="12" height="12"/>';
echo $_SESSION['up'];
unset($_SESSION['up']);
}

}
	?>
	</font>
	  </div>
  </div>
</div>
<div id="sidebar">
<br/>
<div id="partners" class="boxed">
			<h2 class="title">TEACHERS</h2>
            </div>
            <?php
include_once "menu.php";
?>
 <?php
include_once "../footer.php";
}
?>

</body>
</html>